package io.gitee.guoguoleo.utils;

import cn.hutool.core.util.StrUtil;
import io.gitee.guoguoleo.annotation.JokerTable;
import org.apache.commons.lang3.StringUtils;

public class TableUtil {

    /**
     * 获取表名
     *
     * @param clazz 类
     * @return 表名
     */
    public static <T> String getTableName(Class<T> clazz) {
        JokerTable jokerTable = clazz.getAnnotation(JokerTable.class);
        if (jokerTable == null) {
            return StrUtil.toUnderlineCase(clazz.getSimpleName());
        } else {
            if (StringUtils.isBlank(jokerTable.value())) {
                return StrUtil.toUnderlineCase(clazz.getSimpleName());
            } else {
                return jokerTable.value();
            }
        }
    }

}
